/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('nbf', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model AddRequest {
  x?: int32(name='x'),
  y?: int32(name='y'),
}

model AddResponseBody = {
  sum?: int32(name='sum'),
}

model AddResponse = {
  headers: map[string]string(name='headers'),
  body: AddResponseBody(name='body'),
}

async function add(request: AddRequest): AddResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return addWithOptions(request, headers, runtime);
}

async function addWithOptions(request: AddRequest, headers: map[string]string, runtime: Util.RuntimeOptions): AddResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.x)) {
    query.x = request.x;
  }
  if (!Util.isUnset(request.y)) {
    query.y = request.y;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  return doROARequest('Add', '2021-09-14_16-39-42-8', 'HTTPS', 'GET', 'AK', `/caiheRoaProduct/8_0_0/add`, 'json', req, runtime);
}

model MultiComplexRequest {
  arg0?: readable(name='arg0'),
  arg1?: int32(name='arg1'),
  arg2?: {
    stringValue?: readable(name='stringValue'),
    intValue?: int32(name='intValue'),
    booleanValue?: boolean(name='booleanValue'),
    integerValue?: int32(name='integerValue'),
    longValue?: long(name='longValue'),
    secondInput?: {
      secondString?: readable(name='secondString'),
      thirdList?: [ 
        {
          thirdInt?: int32(name='thirdInt'),
          thirdString?: readable(name='thirdString'),
        }
      ](name='thirdList'),
      secondInt?: int32(name='secondInt'),
    }(name='secondInput'),
  }(name='arg2'),
}

model MultiComplexShrinkRequest {
  arg0?: readable(name='arg0'),
  arg1?: int32(name='arg1'),
  arg2Shrink?: string(name='arg2'),
}

model MultiComplexResponseBody = {
  stringValue?: readable(name='stringValue'),
  secondOutput?: {
    secondString?: readable(name='secondString'),
    thirdList?: [ 
      {
        thirdInt?: int32(name='thirdInt'),
        thirdString?: readable(name='thirdString'),
      }
    ](name='thirdList'),
    secondInt?: int32(name='secondInt'),
  }(name='secondOutput'),
  intValue?: int32(name='intValue'),
  booleanValue?: boolean(name='booleanValue'),
  integerValue?: int32(name='integerValue'),
  longValue?: long(name='longValue'),
}

model MultiComplexResponse = {
  headers: map[string]string(name='headers'),
  body: MultiComplexResponseBody(name='body'),
}

async function multiComplex(request: MultiComplexRequest): MultiComplexResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return multiComplexWithOptions(request, headers, runtime);
}

async function multiComplexWithOptions(tmpReq: MultiComplexRequest, headers: map[string]string, runtime: Util.RuntimeOptions): MultiComplexResponse {
  Util.validateModel(tmpReq);
  var request = new MultiComplexShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.arg2)) {
    request.arg2Shrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.arg2, 'arg2', 'json');
  }
  var query : map[string]any= {};
  if (!Util.isUnset(request.arg0)) {
    query.arg0 = request.arg0;
  }
  if (!Util.isUnset(request.arg1)) {
    query.arg1 = request.arg1;
  }
  if (!Util.isUnset(request.arg2Shrink)) {
    query.arg2 = request.arg2Shrink;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  return doROARequest('MultiComplex', '2021-09-14_16-39-42-8', 'HTTPS', 'POST', 'AK', `/caiheRoaProduct/8_0_0/multiComplex`, 'json', req, runtime);
}

